package group2projman;

import group2projman.Transaction.Type;

import java.text.SimpleDateFormat;

public class Return extends BookTransaction {
	int lateFee;
	
	public Return(int id, int bookCopyId, int lateFee) {
		super(id, bookCopyId, Transaction.Type.RETURN);
		
		this.lateFee = lateFee;
	}
	
	public String listAttributes() {
		StringBuffer result = new StringBuffer(super.listAttributes());
				
		result.append(",str:bookCopyId;").append(0);
		result.append(",dat:dueDate;").append(0);
		result.append(",int:lateFee;").append(lateFee);
		result.append(",int:").append("amount;").append(0);
		result.append(",STR:description;").append(0);
		
		return result.toString();
	}
	
	public boolean loadAttributes(String desc) {
		if (super.loadAttributes(desc))
			return true;
		
		try {
			String[] split = desc.split("[;,]");	
			
			if (!split[10].equals("int:lateFee"))
				return true;	
			lateFee = Integer.parseInt(split[11]);					
		}  catch (Exception e) {
			// Array index out of bounds or enum value not found
			return true;
		}
		
		return false;
	}
}
